import fetchHttp from '@/fetch';

const validateTitle = async (rule, value, callback) => {
  const existed = await fetchHttp.get(`/room-types/exist?title=${value.trim()}`, null, false, false);
  if (value && existed) {
    return callback(new Error("已存在的房型名称"));
  }
  callback();
};


export default {
  title: [{
      required: true,
      message: "请输入房型名称",
      trigger: "blur"
    },
    {
      min: 2,
      max: 16,
      message: "房型名称长度为2~16位",
      trigger: "blur"
    },
    {
      validator: validateTitle,
      trigger: "blur"
    }
  ],
  isBed: {
    required: true,
    message: '是否为床位房型标识项不能为空',
    trigger: 'blur'
  }
}
